﻿using System.Net;
using System.Web.Mvc;
using Enyim.Caching;
using SilenthinkContract;
using SilenthinkService;
using Web.Manage.Models;
using SilenthinkContract.Domain;

namespace Web.Manage.Controllers
{
    public class PromotionController : BaseController
    {
        public PromotionController(ILogService logService, IBaseService baseService, IExtraService extraService, IStoreService storeService, IOrderService orderService, IGameService gameService, IAuctionService auctionService, IPassportService passportService, IPaymentService paymentService, IMemcachedClient memcachedClient) : base(logService, baseService, extraService, storeService, orderService, gameService, auctionService, passportService, paymentService, memcachedClient)
        {
        }

        public ActionResult Discount(int size = 20, int index = 1, DiscountAssignedTo? assignedTo = null, bool? usePercentage = null, bool? status = null)
        {
            var model = new PromotionControllerModel.DiscountList();
            model.Discounts =StoreService.GetPagedDiscount(size, index, assignedTo, usePercentage, status).ToPagedList(index, size);
            return View(model);
        }

        public ActionResult Requirement(int param)
        {
            ViewBag.DiscountId = param;
            ViewBag.RequirementRule = DiscountRequirement.GetRequirementRuleDic();
            var model = StoreService.GetDiscountRequirement(param);
            return View(model);
        }

        [HttpPost]
        public ActionResult CreateRequirement(int param, DiscountRequirement requirement)
        {
            requirement.DiscountId = param;
            var result = StoreService.CreateDiscountRequirement(requirement);
            return result ? Json(HttpStatusCode.OK, "成功", "/Promotion/Requirement", "/Promotion/Requirement/" + param) : Json(HttpStatusCode.BadRequest, "添加失败");
        }
    }
}
